summaryrefslogtreecommitdiffstats
path: root/src/audio_core/renderer/audio_renderer.cpp
blob: 51aa17599e7650fc56ac8e58da422addd08f3005 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
// SPDX-FileCopyrightText: Copyright 2022 yuzu Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later

#include "audio_core/audio_render_manager.h"
#include "audio_core/common/audio_renderer_parameter.h"
#include "audio_core/renderer/audio_renderer.h"
#include "audio_core/renderer/system_manager.h"
#include "core/core.h"
#include "core/hle/kernel/k_transfer_memory.h"
#include "core/hle/service/audio/errors.h"

namespace AudioCore::AudioRenderer {

Renderer::Renderer(Core::System& system_, Manager& manager_, Kernel::KEvent* rendered_event)
    : core{system_}, manager{manager_}, system{system_, rendered_event} {}

Result Renderer::Initialize(const AudioRendererParameterInternal& params,
                            Kernel::KTransferMemory* transfer_memory,
                            const u64 transfer_memory_size, const u32 process_handle,
                            const u64 applet_resource_user_id, const s32 session_id) {
    if (params.execution_mode == ExecutionMode::Auto) {
        if (!manager.AddSystem(system)) {
            LOG_ERROR(Service_Audio,
                      "Both Audio Render sessions are in use, cannot create any more");
            return Service::Audio::ERR_MAXIMUM_SESSIONS_REACHED;
        }
        system_registered = true;
    }

    initialized = true;
    system.Initialize(params, transfer_memory, transfer_memory_size, process_handle,
                      applet_resource_user_id, session_id);

    return ResultSuccess;
}

void Renderer::Finalize() {
    auto session_id{system.GetSessionId()};

    system.Finalize();

    if (system_registered) {
        manager.RemoveSystem(system);
        system_registered = false;
    }

    manager.ReleaseSessionId(session_id);
}

System& Renderer::GetSystem() {
    return system;
}

void Renderer::Start() {
    system.Start();
}

void Renderer::Stop() {
    system.Stop();
}

Result Renderer::RequestUpdate(std::span<const u8> input, std::span<u8> performance,
                               std::span<u8> output) {
    return system.Update(input, performance, output);
}

} // namespace AudioCore::AudioRenderer